import re

import scrapy


class YuhangSpider(scrapy.Spider):
    name = 'yuhang'
    allowed_domains = ['yuhang.gov.cn']
    start_urls = ['http://www.yuhang.gov.cn/art/2023/8/1/art_1229176201_4188915.html']

    def parse(self, response):
        title = response.css("div.article-title > h3").extract_first()
        content = response.css("div.article-content").extract_first()

        yield {
            'title': re.sub(r'<[^>]+>', '', title) ,
            'content': re.sub(r'<[^>]+>', '', content) 
        }

        href = response.css("div.article-content > a:last-child").attrib['href']
        next_page_url = "http://www.yuhang.gov.cn{}".format(href)
        yield scrapy.Request(url=next_page_url,callback=self.parse)
